package com.money.tracker.auth.service.impl;

import cn.dev33.satoken.stp.StpInterface;
import com.money.tracker.common.entity.LoginUser;
import com.money.tracker.common.utils.LoginUtil;
import com.money.tracker.common.enums.UserTypeEnum;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * sa-token 权限管理实现类
 *
 * @author Lion Li
 */
public class SaPermissionImpl implements StpInterface {
    @Override
    public List<String> getPermissionList(Object o, String s) {
        LoginUser loginUser = LoginUtil.getLoginUser();
        if (Objects.isNull(loginUser)) {
            return new ArrayList<>();
        }
        UserTypeEnum userTypeEnum = UserTypeEnum.getUserType(loginUser.getUserType());
        if (userTypeEnum == UserTypeEnum.SYS_USER) {
            return new ArrayList<>(loginUser.getMenuPermission());
        }
        if (userTypeEnum == UserTypeEnum.APP_USER) {
            // 其他端 自行根据业务编写
        }
        return new ArrayList<>();
    }

    @Override
    public List<String> getRoleList(Object o, String s) {
        LoginUser loginUser = LoginUtil.getLoginUser();
        if (Objects.isNull(loginUser)) {
            return new ArrayList<>();
        }
        UserTypeEnum userTypeEnum = UserTypeEnum.getUserType(loginUser.getUserType());
        if (userTypeEnum == UserTypeEnum.SYS_USER) {
            return new ArrayList<>(loginUser.getRolePermission());
        }
        if (userTypeEnum == UserTypeEnum.APP_USER) {
            // 其他端 自行根据业务编写
        }
        return new ArrayList<>();
    }
}
